package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.RequiredPackReqVO;
import com.yunxi.otd.pojo.VehicleConfigConstraintVO;
import com.yunxi.otd.service.VehicleConfigConstraintDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 整车配置约束规则 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-08-05
 */
@RestController
@RequestMapping("/admin/otd/constraint")
@Api(tags = "OTD:CONSTRAINT", description = "整车配置约束规则接口")
public class VehicleConfigConstraintController {

    private static final Logger logger = LoggerFactory.getLogger(VehicleConfigConstraintController.class);

    @Autowired
    VehicleConfigConstraintDubboService vehicleConfigConstraintDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(VehicleConfigConstraintVO vehicleConfigConstraintVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil
            .ok(vehicleConfigConstraintDubboService.findPageByVO(vehicleConfigConstraintVO, pageNum, pageSize));
    }

    @GetMapping("/export")
    @ApiOperation(value = "导出")
    public ApiResult list(VehicleConfigConstraintVO vehicleConfigConstraintVO) {
        return ResponseUtil.ok(vehicleConfigConstraintDubboService.listByVo(vehicleConfigConstraintVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(VehicleConfigConstraintVO vehicleConfigConstraintVO) {
        return ResponseUtil.ok(vehicleConfigConstraintDubboService.getById(vehicleConfigConstraintVO.getId()));
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除")
    public ApiResult remove(@RequestBody List<String> ids) {
        vehicleConfigConstraintDubboService.removeByIds(ids);
        return ResponseUtil.ok();
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody VehicleConfigConstraintVO vehicleConfigConstraintVO) {
        vehicleConfigConstraintDubboService.saveOrUpdate(vehicleConfigConstraintVO);
        return ResponseUtil.ok();
    }

    @GetMapping("/export/config")
    @ApiOperation(value = "导出单车配置")
    public ApiResult exportVehicleConfig(String vehicleCode, String inColor, String outColor, String packages) {
        return vehicleConfigConstraintDubboService.getEngineeringConfig(vehicleCode, inColor, outColor, packages);
    }

    @PostMapping("/pack/exclude")
    @ApiOperation(value = "获取互斥选装包")
    public ApiResult findExcludeCustomPackCode (@RequestBody List<String> packages) {
        return vehicleConfigConstraintDubboService.findExcludeCustomPackCode(packages);
    }

    @PostMapping("/pack/required")
    @ApiOperation(value = "根据颜色获取必选选装包")
    public ApiResult findRequiredPackagesByFeatureCode(@RequestBody RequiredPackReqVO requiredPackReqVO) {
        return ResponseUtil.ok(vehicleConfigConstraintDubboService
            .findRequiredPackagesByFeatureCode(requiredPackReqVO.getColorCode(), requiredPackReqVO.getVehicleCode()));
    }
}
